package com.hx.springboot1.utils;

/**
 * Author: hx
 * Date: 2021-05-26 16/56
 * Description: Nothing else
 */
public class checkPwdUtils {
        /**
         * 密码强度
         *
         * @return Z = 字母 S = 数字 T = 特殊字符
         */

	/*  一、假定密码字符数范围6-16，除英文数字和字母外的字符都视为特殊字符：
    弱：^[0-9A-Za-z]{6,16}$
    中：^(?=.{6,16})[0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*$
    强：^(?=.{6,16})([0-9A-Za-z]*[^0-9A-Za-z][0-9A-Za-z]*){2,}$
    二、假定密码字符数范围6-16，密码字符允许范围为ASCII码表字符：
    弱：^[0-9A-Za-z]{6,16}$
    中：^(?=.{6,16})[0-9A-Za-z]*[\x00-\x2f\x3A-\x40\x5B-\xFF][0-9A-Za-z]*$
    强：^(?=.{6,16})([0-9A-Za-z]*[\x00-\x2F\x3A-\x40\x5B-\xFF][0-9A-Za-z]*){2,}$*/
        public static String checkPassword(String passwordStr) {
            String regexZ = "\\d*";
            String regexS = "[a-zA-Z]+";
            String regexT = "\\W+$";
            String regexZT = "\\D*";
            String regexST = "[\\d\\W]*";
            String regexZS = "\\w*";
            String regexZST = "[\\w\\W]*";
            if (passwordStr.length()<6||passwordStr.length()>16){
                return "密码需在6-16位范围内";
            }
            if (passwordStr.matches(regexZ)) {
                return "弱";
            }
            if (passwordStr.matches(regexS)) {
                return "弱";
            }
            if (passwordStr.matches(regexT)) {
                return "弱";
            }
            if (passwordStr.matches(regexZT)) {
                return "中";
            }
            if (passwordStr.matches(regexST)) {
                return "中";
            }
            if (passwordStr.matches(regexZS)) {
                return "中";
            }
            if (passwordStr.matches(regexZST)) {
                return "强";
            }
            return passwordStr;
        }
}

